<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>GoPan 个人网盘 - 登录</title>
  <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    html {
      height: 100%;
      margin: 0;
      padding: 0;
      width: 100%;
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
      height: 100vh;
      width: 100%;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: row;
      overflow: hidden;
    }

    #app {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: row;
    }

    [v-cloak] {
      display: none;
    }

    /* 左侧背景区域 - 黄金分割 61.8% */
    .login-left {
      flex: 0 0 61.8%;
      width: 61.8%;
      background: url('images/login.jpg') center center / cover no-repeat;
      position: relative;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100vh;
    }

    /* 背景遮罩层 */
    .login-left::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(102, 126, 234, 0.3);
      z-index: 0;
    }

    .login-left-content {
      position: relative;
      z-index: 1;
      text-align: center;
      color: white;
      padding: 40px;
    }

    .login-left-content h1 {
      font-size: 3rem;
      font-weight: 700;
      margin-bottom: 1rem;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    }

    .login-left-content p {
      font-size: 1.2rem;
      opacity: 0.9;
      line-height: 1.6;
    }

    /* 右侧登录区域 - 黄金分割 38.2% */
    .login-right {
      flex: 0 0 38.2%;
      width: 38.2%;
      background: #ffffff;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 60px 40px;
      box-shadow: -4px 0 20px rgba(0, 0, 0, 0.05);
      height: 100vh;
      overflow-y: auto;
      position: relative;
    }

    .login-form-container {
      width: 100%;
      max-width: 400px;
      margin: auto;
    }

    /* 网盘 Icon 区域 */
    .login-icon {
      text-align: center;
      margin-bottom: 3rem;
    }

    .icon-wrapper {
      display: inline-block;
      width: 100px;
      height: 100px;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
      margin-bottom: 1.5rem;
    }

    .icon-wrapper svg {
      width: 60px;
      height: 60px;
      fill: white;
    }

    .login-title {
      font-size: 1.8rem;
      font-weight: 600;
      color: #1a202c;
      margin-bottom: 0.5rem;
    }

    .login-subtitle {
      font-size: 0.95rem;
      color: #718096;
    }

    /* 表单区域 */
    .login-form {
      width: 100%;
    }

    .form-group {
      margin-bottom: 1.5rem;
    }

    .form-group label {
      display: block;
      font-size: 0.875rem;
      font-weight: 500;
      color: #4a5568;
      margin-bottom: 0.5rem;
    }

    .form-group input {
      width: 100%;
      padding: 12px 16px;
      font-size: 1rem;
      border: 2px solid #e2e8f0;
      border-radius: 8px;
      transition: all 0.3s ease;
      outline: none;
    }

    .form-group input:focus {
      border-color: #667eea;
      box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }

    .login-button {
      width: 100%;
      padding: 14px;
      font-size: 1rem;
      font-weight: 600;
      color: white;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border: none;
      border-radius: 8px;
      cursor: pointer;
      transition: all 0.3s ease;
      box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
      margin-top: 0.5rem;
    }

    .login-button:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    }

    .login-button:active {
      transform: translateY(0);
    }

    .login-button:disabled {
      opacity: 0.6;
      cursor: not-allowed;
      transform: none;
    }

    .error-message {
      margin-top: 1rem;
      padding: 12px;
      background: #fee;
      border: 1px solid #fcc;
      border-radius: 8px;
      color: #c33;
      font-size: 0.875rem;
      text-align: center;
    }

    .register-link {
      text-align: center;
      margin-top: 1.5rem;
      font-size: 0.875rem;
      color: #718096;
    }

    .register-link a {
      color: #667eea;
      text-decoration: none;
      font-weight: 500;
    }

    .register-link a:hover {
      text-decoration: underline;
    }

    /* 响应式设计 */
    @media (max-width: 768px) {
      body {
        flex-direction: column;
      }

      .login-left {
        flex: 0.4;
        min-height: 200px;
      }

      .login-right {
        flex: 1;
      }

      .login-left-content h1 {
        font-size: 2rem;
      }

      .login-left-content p {
        font-size: 1rem;
      }
    }
  </style>
</head>
<body>
  <div id="app" v-cloak>
    <!-- 左侧背景区域 -->
    <div class="login-left">
      <div class="login-left-content">
        <h1>GoPan</h1>
        <p>安全、便捷的个人云存储服务</p>
        <p style="margin-top: 1rem; font-size: 1rem; opacity: 0.8;">让您的文件随时随地触手可及</p>
      </div>
    </div>

    <!-- 右侧登录区域 -->
    <div class="login-right">
      <div class="login-form-container">
        <!-- 网盘 Icon -->
        <div class="login-icon">
          <div class="icon-wrapper">
            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
              <path d="M10 4H4c-1.11 0-2 .89-2 2v12c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V8c0-1.11-.89-2-2-2h-8l-2-2z"/>
            </svg>
          </div>
          <h2 class="login-title">欢迎回来</h2>
          <p class="login-subtitle">登录您的账户以继续</p>
        </div>

        <!-- 登录表单 -->
        <form class="login-form" @submit.prevent="login">
          <div class="form-group">
            <label for="username">用户名</label>
            <input
              id="username"
              type="text"
              v-model="username"
              placeholder="请输入用户名"
              autocomplete="username"
              required
            />
          </div>

          <div class="form-group">
            <label for="password">密码</label>
            <input
              id="password"
              type="password"
              v-model="password"
              placeholder="请输入密码"
              autocomplete="current-password"
              required
            />
          </div>

          <button type="submit" class="login-button" :disabled="loading">
            {{ loading ? '登录中...' : '登录' }}
          </button>

          <div v-if="error" class="error-message">
            {{ error }}
          </div>

          <div class="register-link">
            还没有账户？<a href="/register.html">立即注册</a>
          </div>
        </form>
      </div>
    </div>
  </div>

  <script>
    const { createApp, ref } = Vue

    createApp({
      setup() {
        const username = ref('')
        const password = ref('')
        const error = ref('')
        const loading = ref(false)

        const login = async () => {
          error.value = ''
          
          if (!username.value || !password.value) {
            error.value = '请输入用户名和密码'
            return
          }

          loading.value = true

          try {
            const res = await fetch('/api/v1/login', {
              method: 'POST',
              headers: { 'Content-Type': 'application/json' },
              body: JSON.stringify({
                username: username.value,
                password: password.value
              }),
              credentials: 'include'
            })

            if (!res.ok) {
              const result = await res.json()
              error.value = result.error || '登录失败，请检查用户名和密码'
              loading.value = false
              return
            }

            // 登录成功，跳转主页面
            window.location.href = '/dashboard.html'
          } catch (err) {
            error.value = '网络错误，请稍后重试'
            loading.value = false
          }
        }

        return { username, password, login, error, loading }
      }
    }).mount('#app')
  </script>
</body>
</html>
